package cn.edu.zafu.bigdata.lhff;

import java.util.Random;
import java.util.Scanner;

public class GuessNumberGame {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int numberToGuess = random.nextInt(100) + 1;
        int attempts = 0;
        int maxAttempts = 6;

        System.out.println("一起玩猜数字游戏吧！你有" + maxAttempts + "次机会来猜一个1到100之间的数字。");

        while (attempts < maxAttempts) {
            System.out.print("请输入你猜测的数字：");
            int guess = scanner.nextInt();
            attempts++;

            if (guess < numberToGuess) {
                System.out.println("数字小了哦！");
            } else if (guess > numberToGuess) {
                System.out.println("数字太大了！");
            } else {
                System.out.println("恭喜你，幸运之神！正确数字是 " + numberToGuess);
                return;
            }
        }

        System.out.println("很遗憾没有猜对，正确的数字是 " + numberToGuess + "。");
        scanner.close();
    }
}
